package com.luo.gmall.order.controller;

import com.luo.gmall.common.bean.ResponseVo;
import com.luo.gmall.order.service.OrderService;
import com.luo.gmall.order.vo.ConfirmVo;
import com.luo.gmall.order.vo.OrderSubmitVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author Zoro
 * @date 2021年11月25
 */
@Controller
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 获取确认订单的数据
     * @param model
     * @return
     */
    @GetMapping("confirm")
    public String confirm(Model model){
        ConfirmVo confirmVo = orderService.confirm();
        model.addAttribute("confirmVo",confirmVo);
        return "trade";
    }



    @PostMapping("submit")
    @ResponseBody
    public ResponseVo<String> submit(@RequestBody OrderSubmitVo orderSubmitVo){

        orderService.submit(orderSubmitVo);

        return ResponseVo.ok(orderSubmitVo.getOrderToken());
    }

}
